package com.zat.mes.andrmes.dofun.main.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.HomeBtnBean

/**
 * @author zy
 * @date :2020-02-13 15:45
 * @description:首页菜单滑动adapter
 */
class HomeVpAdapter : RecyclerView.Adapter<HomeVpAdapter.PagerViewHolder>() {

    private var mList: List<MutableList<HomeBtnBean>> = ArrayList()
    var context: Context? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagerViewHolder {
        context = parent.context
        val itemView = LayoutInflater.from(context).inflate(R.layout.item_vp_page, parent, false)
        return PagerViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: PagerViewHolder, position: Int) {
        var homeBtnAdapter: HomeBtnAdapter = HomeBtnAdapter(R.layout.item_btn_rv_home)
        homeBtnAdapter.addData(mList.get(position))
        val gridLayoutManager = GridLayoutManager(context, 4)
        holder.recyclerView.layoutManager = gridLayoutManager
        holder.recyclerView.adapter = homeBtnAdapter


    }

    /**
     * 设置数据
     */
    fun setList(list: List<MutableList<HomeBtnBean>>) {
        mList = list
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    //  ViewHolder需要继承RecycleView.ViewHolder
    class PagerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val recyclerView: RecyclerView = itemView.findViewById(R.id.recylerItemHome)


    }
}